package cn.clx.basic.service.impl;

import cn.clx.basic.mapper.BaseMapper;
import cn.clx.basic.query.BaseQuery;
import cn.clx.basic.service.IBaseService;
import cn.clx.basic.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;


@Transactional
public class BaseServiceImpl<T> implements IBaseService<T> {

    @Autowired
    private BaseMapper<T>  Mapper;

    @Override
    public void save(T t) {
        Mapper.save(t);
    }

    @Override
    public void update(T t) {
        Mapper.update(t);
    }

    @Override
    public void removeById(Long id) {
        Mapper.deleteById(id);
    }

    @Override
    public List<T> queryAll() {
        return Mapper.loadAll();
    }

    @Override
    public T queryById(Long id) {
        return Mapper.loadById(id);
    }

    @Override
    public PageList<T> queryPage(BaseQuery Query) {
        Long total = Mapper.queryCount(Query);
        List<T> data = Mapper.queryData(Query);
        PageList<T> deptpartmentPageList = new PageList<>();
        deptpartmentPageList.setData(data);
        deptpartmentPageList.setTotal(total);

        return deptpartmentPageList;
    }
}
